//
//  EmoticonTipView.swift
//  VVbo
//
//  Created by Mr.Run on 2017/9/13.
//  Copyright © 2017年 Mr.Run. All rights reserved.
//

import UIKit
import pop

class EmoticonTipView: UIImageView {
    
    private var preEmoticon: Emoticon?
    
    var emoticon: Emoticon? {
        didSet{
            
            if emoticon == preEmoticon {
                return
            }
            
            preEmoticon = emoticon
            tipBtn.setTitle(emoticon?.emoji, for: [])
            tipBtn.setImage(emoticon?.image, for: [])
            
            let anim:POPSpringAnimation = POPSpringAnimation(propertyNamed: kPOPLayerPositionY)
            anim.toValue = 8
            anim.fromValue = 20
            anim.springSpeed = 20
            anim.springBounciness = 20
            tipBtn.layer.pop_add(anim, forKey: nil)
        }
    }
    
    fileprivate lazy var tipBtn = UIButton()
    
    init(){
        let bundle = EmoticonManager.shared.bundle
        let image = UIImage(named: "emoticon_keyboard_magnifier", in: bundle, compatibleWith: nil)
        super.init(image: image)
        layer.anchorPoint = CGPoint(x: 0.5, y: 1.2)
        tipBtn.layer.anchorPoint = CGPoint(x: 0.5, y: 0)
        tipBtn.frame = CGRect(x: 0, y: 8, width: 36, height: 36)
        tipBtn.center.x = bounds.width*0.5
        tipBtn.setTitle("😆", for: [])
        tipBtn.titleLabel?.font = UIFont.systemFont(ofSize: 32)
        addSubview(tipBtn)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
